<?php

class orm
{
	public $_table;
	public $_tableModel;
	public $_fields;
	public $_primaryKey;
	public $_isLocalized;
	
	public function __construct()
	{
		$this->_tableModel = ucfirst(get_class($this) . 's'); //todo: if model is a singleton then this is nice...
	}
	
	public function setFields($fields)
	{
		//todo: remove this shit and just link to the table model? too much recursion?
		$this->_fields = $fields;
		
		foreach($this->_fields as $field)
		{
			$this->${$field->name} = null;
			
			if ($field->primaryKey)
			{
				$this->_primaryKey = $this->${$field->name};
			}
		}
	}
	
	public function populate($data)
	{
		//todo: check if fields are set.
		foreach($data as $key=>$value)
		{
			if (isset($this->${$key}))
			{
				$this->${$key} = $value; //todo: should there be a check for quotes and stuff?
			}
		}
	}
	
	public function save()
	{
		
	}
	
	public function discard()
	{
		
	}
	
	public function delete()
	{
		
	}
	
	public function refresh()
	{
		
	}
}

?>